package com.ktgj.hotel.controller;

import java.math.BigDecimal;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.common.core.constant.CustomerConstants;
import com.ktgj.common.core.domain.R;
import com.ktgj.customer.api.RemoteCustomerService;
import com.ktgj.customer.api.domain.Customer;
import com.ktgj.hotel.domain.HotelOrderRoom;
import com.ktgj.hotel.domain.vo.*;
import com.ktgj.hotel.service.IHotelOrderRefundapplyService;
import com.ktgj.hotel.service.IHotelOrderRoomService;
import com.ktgj.hotel.service.impl.HotelOrderRoomServiceImpl;
import com.ktgj.pay.api.domain.WXConfigApi;
import com.ktgj.pay.api.domain.WXPayUtilApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.hotel.domain.HotelOrder;
import com.ktgj.hotel.service.IHotelOrderService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@ControllerAdvice
@RestController
@RequestMapping("/order")
public class HotelOrderController extends BaseController
{
    private static IHotelOrderService hotelOrderService;

    @Autowired
    public void setRedisTemplate(IHotelOrderService hotelOrderService)
    {
        HotelOrderController.hotelOrderService = hotelOrderService;
    }

    @Autowired
    private IHotelOrderRoomService hotelOrderRoomService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:order:list")
    @GetMapping("/list")
    public TableDataInfo list(HotelOrder hotelOrder)
    {
        startPage();
        List<HotelOrder> list = hotelOrderService.selectHotelOrderList(hotelOrder);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:order:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotelOrder hotelOrder) throws IOException
    {
        List<HotelOrder> list = hotelOrderService.selectHotelOrderList(hotelOrder);
        ExcelUtil<HotelOrder> util = new ExcelUtil<HotelOrder>(HotelOrder.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping("/getInfo")
    public AjaxResult getInfo(@RequestParam("orderid") Long orderid)
    {
        return AjaxResult.success(hotelOrderService.selectHotelOrderById(orderid));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:order:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotelOrder hotelOrder)
    {
        return toAjax(hotelOrderService.insertHotelOrder(hotelOrder));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PostMapping("/editHotelOrder")
    public AjaxResult editHotelOrder(@RequestBody HotelOrder hotelOrder)
    {
        return toAjax(hotelOrderService.updateHotelOrder(hotelOrder));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:order:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderids}")
    public AjaxResult remove(@PathVariable Long[] orderids)
    {
        return toAjax(hotelOrderService.deleteHotelOrderByIds(orderids));
    }

    /**
     * 查询酒店订单量
     */
    @PostMapping("/hotelOrderNum")
    public List<HotelOrder> hotelOrderNum(@RequestBody Map<String, Object> map)
    {
        Long customerId = Long.valueOf(map.get("customerId").toString());
        List<HotelOrder> hotelOrders = hotelOrderService.selectHotelOrderNum(customerId);
        if (hotelOrders != null && hotelOrders.size() > 0)
        {
            return hotelOrders;
        } else
        {
            return null;
        }
    }

    /**
     * 酒店订单
     */
    @PostMapping("/orderDetails")
    public AjaxResult orderDetails(@RequestBody Map<String, Object> map)
    {
        if (map.get("orderId") != null && !map.get("orderId").equals(""))
        {
            Long orderId = Long.valueOf(map.get("orderId").toString());
            HotelDetailsOrderVo hotelDetailsOrderVo = hotelOrderService.orderDetails(orderId);
            return AjaxResult.success(hotelDetailsOrderVo);
        } else
        {
            return AjaxResult.error("缺少必要参数");
        }
    }

    @PostMapping("/queryHotelOrderNumber")
    public int queryHotelOrderNumber(@RequestBody Long customerId)
    {
        return hotelOrderService.queryHotelOrderNumber(customerId);
    }

    /**
     * 行程酒店订单
     */
    @PostMapping("/journeyHotelVo")
    public JourneyHotelVo journeyHotelVo(@RequestBody Map<String, Object> map)
    {
        Long orderId = Long.valueOf(map.get("orderId").toString());
        JourneyHotelVo journeyHotelVo = hotelOrderService.checkHotel(orderId);
        return journeyHotelVo;
    }

    /**
     * 酒店订单退单详情
     */
    @PostMapping("/hotelRetreat")
    public AjaxResult hotelRetreat(@RequestBody Map<String, Object> map)
    {
        Long id = Long.valueOf(map.get("id").toString());
        HotelRetreatVo hotelRetreatVo;
        try
        {
            hotelRetreatVo = hotelOrderService.hotelRetreat(id);
        } catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success(hotelRetreatVo);
    }

    /**
     * 酒店取消预定订单
     */
    @PostMapping("/hotelCancelOrderList")
    private TableDataInfo hotelCancelOrderList(@RequestBody HotelCancelOrderVo hotelCancelOrderVo)
    {
        startPage();
        List<HotelReturnVo> hotelReturnVoList;
        try
        {
            hotelReturnVoList = hotelOrderService.hotelCancelOrderList(hotelCancelOrderVo);
        } catch (Exception e)
        {
            return null;
        }

        return getDataTable(hotelReturnVoList);
    }

    /**
     * 订单id获取酒店订单信息
     */
    @PostMapping("/order")
    public HotelOrder order(@RequestBody Map<String, Object> map)
    {
        Long orderId = Long.valueOf(map.get("orderId").toString());
        HotelOrder hotelOrder = hotelOrderService.selectHotelOrderById(orderId);
        return hotelOrder;
    }

    /**
     * 订单号获取酒店订单信息
     */
    @PostMapping("/orderNum")
    public HotelOrder orderNum(@RequestBody Map<String, Object> map)
    {
        String orderNum = map.get("orderNum").toString();
        HotelOrder hotelOrder = hotelOrderService.orderNum(orderNum);
        return hotelOrder;
    }

    /**
     * 获取酒店的待跟进订单
     *
     * @return
     */
    @PostMapping("/hotelOrderListThings")
    public List<HotelOrder> orderListThings()
    {
        return hotelOrderService.orderListThings();
    }
}
